<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Carousel Component Example - Slide Show</title>
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">

	<script type="text/javascript" src="http://yui.yahooapis.com/combo?2.6.0/build/utilities/utilities.js&2.6.0/build/container/container_core-min.js"></script> 
	<script type="text/javascript" src="scripts/carousel.js"></script>

	<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/combo?2.6.0/build/reset-fonts-grids/reset-fonts-grids.css&2.6.0/build/base/base-min.css">
	<link href="css/carousel.css" rel="stylesheet" type="text/css">
	<link href="css/yui.css" rel="stylesheet" type="text/css">

<!-- 
	Inlined styles for my overrides to the carousel for this demo.
	Normally I would put this in a separate CSS file.
-->
<style type="text/css">
.carousel-component .carousel-list li { 
	width:506px; /*500 + 2 + 2 + 1 + 1 */
}

.carousel-component .carousel-list li a { 
	display:block;
	border:2px solid #e2edfa;
	outline:none;
	-moz-outline:none; 
}

.carousel-component .carousel-list li a:hover { 
	border: 2px solid #87bf4e; 
}

.carousel-component .carousel-list li.active a { 
	border:2px solid #708fc7; 
}

.carousel-component .carousel-list li img { 
	border:1px solid #999;
	display:block; 
}
									
.carousel-component .carousel-prev { 
	position:absolute;
	top:30px;
	z-index:3;
	cursor:pointer; 
	left:5px; 
}

.carousel-component .carousel-next { 
	position:absolute;
	top:30px;
	z-index:3;
	cursor:pointer; 
	right:5px; 
}

</style>

<script type="text/javascript">

/**
 * Image src URLs
 **/
var imageList = [
				 "http://static.flickr.com/49/154253308_f9fe62f5bc.jpg",
				 "http://static.flickr.com/48/154252979_e14b8adf6a.jpg",
				 "http://static.flickr.com/58/154252383_d59833136c.jpg",
				 "http://static.flickr.com/70/154251973_f58009862a.jpg",
				 "http://static.flickr.com/48/154251863_c2747e4fa5.jpg",
				 "http://static.flickr.com/73/154251425_07c48d786a.jpg",
				 "http://static.flickr.com/54/154251208_ec14c7295e.jpg",
				 "http://static.flickr.com/49/154250868_9ed96d9fdf.jpg",
				 "http://static.flickr.com/51/154250687_c241e9b5a2.jpg",
				 "http://static.flickr.com/75/154250731_ce18000d85.jpg",
				 "http://static.flickr.com/52/154250543_633506d4cf.jpg",
				 "http://static.flickr.com/44/154250315_fcc6200d4b.jpg",
				 "http://static.flickr.com/72/154249918_2ccc135309.jpg",
				 "http://static.flickr.com/58/154249509_6f5331fa30.jpg",
				 "http://static.flickr.com/57/154249373_be8530cc12.jpg",
				 "http://static.flickr.com/72/154249186_27ed99db61.jpg",
				 "http://static.flickr.com/46/161892486_b4f8b93917.jpg",
				 "http://static.flickr.com/52/161893596_fc5055fe5a.jpg",
				 "http://static.flickr.com/53/161893993_2000af9417.jpg"
				 ];

/**
 * Custom inital load handler. Called when the carousel loads the initial
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadInitHandler
 **/
var loadInitialItems = function(type, args) {

	var start = args[0];
	var last = args[1]; 

	load(this, start, last);	
	var status = "Showing " + start + " of " + this.getProperty("size");
	YAHOO.util.Dom.get("indicator").innerHTML = status;
};

var animComplete = function(type, args) {
	var direction = args[0]; // string either: 'next' or 'prev'
	
	var status = "Showing " + this.getFirstVisible() + " of " + this.getProperty("size");
	YAHOO.util.Dom.get("indicator").innerHTML = status + " (done)";

};

/**
 * Custom load next handler. Called when the carousel loads the next
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadNextHandler
 **/
var loadNextItems = function(type, args) {	

	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
};

/**
 * Custom load previous handler. Called when the carousel loads the previous
 * set of data items. Specified to the carousel as the configuration
 * parameter: loadPrevHandler
 **/
var loadPrevItems = function(type, args) {
	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
}; 

var load = function(carousel, start, last) {
	for(var i=start; i<= last+1; i++) {
		carousel.addItem(i, fmtItem(imageList[i-1]));
	}
}

/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the previous button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: prevButtonStateHandler
 **/
var handlePrevButtonState = function(type, args) {

	var enabling = args[0];
	var leftImage = args[1];
	if(enabling) {
		leftImage.src = "images/left-enabled.gif";
	} else {
		leftImage.src = "images/left-disabled.gif";
	}
	
};

/**
 * Custom button state handler for enabling/disabling button state. 
 * Called when the carousel has determined that the next button
 * state should be changed.
 * Specified to the carousel as the configuration
 * parameter: nextButtonStateHandler
 **/
var handleNextButtonState = function(type, args) {

	var enabling = args[0];
	var rightImage = args[1];
	if(enabling) {
		rightImage.src = "images/right-enabled.gif";
	} else {
		rightImage.src = "images/right-disabled.gif";
	}
	
};

/**
 * You must create the carousel after the page is loaded since it is
 * dependent on an HTML element (in this case 'dhtml-carousel'.) See the
 * HTML code below.
 **/
var carousel; // for ease of debugging; globals generally not a good idea

var pageLoad = function() 
{
	carousel = new YAHOO.extension.Carousel("dhtml-carousel", 
		{
			numVisible:        1,
			animationSpeed:   0.35,
			scrollInc:         1,
			//animationMethod:   YAHOO.util.Easing.backOut,
			navMargin:         40,
			size:         	 18,
			prevElement:     "left-arrow",
			nextElement:     "right-arrow",
			loadInitHandler:   loadInitialItems,
			loadNextHandler:   loadNextItems,
			loadPrevHandler:   loadPrevItems,
			animationCompleteHandler: animComplete,
			prevButtonStateHandler:   handlePrevButtonState,
			nextButtonStateHandler:   handleNextButtonState
		}
	);

};

/**
 * Since carousel.addItem uses an HTML string to create the interface
 * for each carousel item, this method formats the HTML for an LI.
 **/
var fmtItem = function(imgUrl) {
		
  	var innerHTML = 
  		'<a href="#"><img src="' + 
  		imgUrl +
		'"/><\/a>';
  
	return innerHTML;
	
};

YAHOO.util.Event.addListener(window, 'load', pageLoad);

</script>
</head>

<body>
<div id="doc" class="yui-t7">
   <div id="hd">
		<h1>Slide Show - Carousel</h1>
   </div>
<div id="bd">
<p>One image at a time, slide show style. Also illustrates how to indicate which slide we are currently viewing in a separate
status area and how to perform an action when the animation completes. </p> 

<!-- Carousel Structure -->
<div id="dhtml-carousel" class="carousel-component">
	<div class="carousel-prev">
		<img id="left-arrow" class="left-button-image" 
			src="images/left-enabled.gif" alt="Previous Button"/>
	</div>
	<div class="carousel-next">
		<img id="right-arrow" class="right-button-image" 
			src="images/right-enabled.gif" alt="Next Button"/>
	</div>
	<div class="carousel-clip-region">
		<ul class="carousel-list">
			<!-- Filled in via the loadInitHandler, loadNextHandler, and loadPrevHandler
			<li id="item-1">
			<a href="#">
				<img src="http://static.flickr.com/74/162582364_7fc3e2d60d_s.jpg"/>
			</a>Number One</li>
			-->
		</ul>
	</div>
</div>
<div id="indicator"></div>

<div>
<p>The additional parameter for handling animation completion:</p>

<pre>
			animationCompleteHandler: animComplete
</pre>

<p>And the code to handle showing status when navigating and when animation completes:</p>
<pre>
// this == carousel
var loadNextItems = function(type, args) {	

	var start = args[0];
	var last = args[1]; 
	var alreadyCached = args[2];
	
	if(!alreadyCached) {
		load(this, start, last);
	}
	var status = "Showing " + start + " of " + this.getProperty("size");
	YAHOO.util.Dom.get("indicator").innerHTML = status;
};
// this == carousel
var animComplete = function(type, args) {
	var direction = args[0]; // string either: 'next' or 'prev'
	
	var status = "Showing " + this.getProperty("firstVisible") + " of " + this.getProperty("size");
	YAHOO.util.Dom.get("indicator").innerHTML = status + " (done)";
};

</pre>
</div>
<div style="padding-top:20px;clear:both">View the <a href="source.php?url=carousel_slides.html">source</a>&nbsp;or&nbsp;<a href="index.html">documentation</a></div>

</div>
</div> 
</body>
</html>